package com.woniuxy;

import javax.swing.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 作者
 * @create 2025-09-11 9:34
 */
public class Test01 {
    public static void main(String[] args) throws ParseException {
        int year=2000;
        for (;year<=2020;year++) {
            LocalDate localDate = LocalDate.of(year,3,1);
            localDate = localDate.minusDays(1);
            System.out.println(localDate.getDayOfMonth());
        }
    }

    private static void test08() {
        LocalDateTime   localDateTime=LocalDateTime.now();
        System.out.println(localDateTime.getYear());
        System.out.println(localDateTime.get(ChronoField.YEAR));
        LocalDateTime plus = localDateTime.plus(1, ChronoUnit.YEARS);
        System.out.println(localDateTime);
        System.out.println(plus);
    }

    private static void test07() {
        StringBuilder sb=new StringBuilder();
        sb.append("aaa");
        sb.append("bbb");
        System.out.println(sb);
        sb.substring(2);
        System.out.println(sb);
    }

    private static void test06() {
        //        String str="2000-01-01 00:00:00";
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        LocalDateTime localDateTime = LocalDateTime.parse(str, formatter);
//        System.out.println(localDateTime);

        System.out.println(LocalDate.parse("2000-01-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    }

    private static void test05() {
        //LocalDateTime.of()
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);
        //指定日期转换格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String str = formatter.format(localDateTime);
        System.out.println(str);
    }

    private static void test04() {
        Calendar calendar = Calendar.getInstance();
        int year=2000;
        //日历设置为当年的3月1号
        for (;year<=2020;year++) {
            calendar.set(year, 2, 1);
            calendar.add(Calendar.DATE, -1);
            System.out.println(year+"--"+calendar.get(Calendar.DATE));
        }
    }

    private static void test03() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        System.out.println(calendar.get(Calendar.DATE));
    }

    private static void test02() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String str="2000-1-1";
        Date date = sdf.parse(str);
        System.out.println(date);
    }

    private static void test01() {
        Date date = new Date();
        System.out.println(date);
        System.out.println(date.getYear()+1900);
        //日期转字符串
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String str = sdf.format(date);
        System.out.println(str);
    }
}
